import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: paths,
  //   name: 'Home',
  //   component: () => import('../views/home/Home.vue'),
  // },
]

const router = new VueRouter({
  routes,
})

router.beforeEach((to, from, next) => {
  // console.log(to, from)
  let paths = to.path
  let names = to.path.slice(1)
  let ro = {
    path: paths,
    name: names,
    component: () =>
      import(
        '../views/' +
          names +
          '/' +
          names.charAt(0).toUpperCase() +
          names.slice(1)
      ),
  }
  let lef = router.getRoutes().some((item) => item.name == names)
  if (lef) {
    next()
  } else {
    router.addRoute(ro)
    next({ ...ro, replace: true })
  }
})
export default router
